package myky.com.doctorapp.model;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import myky.com.doctorapp.api.ApiManager;
import myky.com.doctorapp.entity.SearchHistoryItem;
import myky.com.doctorapp.base.BaseEntity;
import myky.com.doctorapp.contract.SearchContract;
import myky.com.doctorapp.utils.RequestBodyBuilder;
import okhttp3.RequestBody;

public class SearchModel implements SearchContract.Model {
    @Override
    public Observable<BaseEntity<ArrayList<SearchHistoryItem>>> findAllSearchHistory(String version, String searchScope, String customId) {

        RequestBodyBuilder.Builder builder = new RequestBodyBuilder.Builder();
        builder.params("version", version);
        builder.params("searchScope", searchScope);
        builder.params("customerId", customId);
        RequestBody requestBody = builder.build();
        return ApiManager.getApistore().findHistoryById(requestBody);
    }

    @Override
    public Observable<BaseEntity<Object>> deleteSingleHistoryById(int id, String version, String customId) {

        RequestBodyBuilder.Builder builder = new RequestBodyBuilder.Builder();
        builder.params("id", String.valueOf(id));
        builder.params("version", version);
        builder.params("customerId", customId);
        RequestBody requestBody = builder.build();



        return ApiManager.getApistore().deleteSingleHistoryById(requestBody);
    }

    @Override
    public Observable<BaseEntity<Object>> deleteAllHistoryById(String version, String customId) {
        RequestBodyBuilder.Builder builder = new RequestBodyBuilder.Builder();
        builder.params("version", version);
        builder.params("customerId", customId);
        RequestBody requestBody = builder.build();
        return ApiManager.getApistore().deleteAllHistory(requestBody);
    }

    @Override
    public Observable<BaseEntity<List<String>>> findKeyWordByInput(String version, String searchType, String input) {
        RequestBodyBuilder.Builder builder = new RequestBodyBuilder.Builder();
        builder.params("version", version);
        builder.params("searchType", searchType);
        builder.params("input", input);
        RequestBody requestBody = builder.build();
        return ApiManager.getApistore().findKeyWordByInput(requestBody);
    }
}
